package com.jiukuaidao.zhulin.module.order.presenter;

import android.widget.Toast;

//import com.google.android.gms.common.api.Api;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.jiukuaidao.library.Config;
import com.jiukuaidao.library.net.MyRetroCallBack;
import com.jiukuaidao.library.util.ToastUtil;
import com.jiukuaidao.zhulin.api.ApiGetGoodsComments;
import com.jiukuaidao.zhulin.api.ApiOrderDetail;
import com.jiukuaidao.zhulin.api.ApiPostOrderComment;
import com.jiukuaidao.zhulin.data.TasksRepository;
import com.jiukuaidao.zhulin.entity.ApiOrderCommentPost;
import com.jiukuaidao.zhulin.entity.ApiOrderDetailInfo;
import com.jiukuaidao.zhulin.module.BasePresenter;
import com.jiukuaidao.zhulin.module.order.contract.OrderCommentContract;
import com.jiukuaidao.zhulin.util.ShopInfoUtil;

/**
 * T_winds
 * Date:  16.8.18
 * Description:
 */
public class OrderCommentPresenter extends BasePresenter<OrderCommentContract.View,TasksRepository> implements OrderCommentContract.Presenter{

    public OrderCommentPresenter(TasksRepository repository, OrderCommentContract.View view) {
        super(repository, view);
    }

    /****************************************IBasePresenter**************************************************/
    @Override
    public void loadData() {

        mView.showLoading("加载中..");

        mRepository.loadData(new ApiOrderDetail(mView.getOrderNo(), new MyRetroCallBack<ApiOrderDetailInfo>() {
            @Override
            public void onSuccess(ApiOrderDetailInfo result, String errorCode, String msg) {
                if (result != null){
                    mView.getOrderDetailDataSuc(result);
                }
                mView.hideLoading();
            }

            @Override
            public void onFail(ApiOrderDetailInfo result, String errorCode, String msg) {
                ToastUtil.show(msg, Toast.LENGTH_SHORT);
                mView.hideLoading();
            }

            @Override
            public void onError(Throwable t, int resCode, String msg) {
                if (Config.Debug)
                    ToastUtil.show("errorCode  :" + resCode + "\n errorMsg :" + msg, Toast.LENGTH_SHORT);

                mView.hideLoading();
            }
        }));

    }



    /***************************************OrderCommentContract.Presenter***************************************************/
    @Override
    public void postComment() {

        ApiOrderCommentPost mCommentPost = mView.getCommentPost();
        mRepository.loadData(new ApiPostOrderComment(mCommentPost, new MyRetroCallBack<Object>() {
            @Override
            public void onSuccess(Object result, String errorCode, String msg) {
                mView.postCommentSuc();
            }

            @Override
            public void onFail(Object result, String errorCode, String msg) {
                ToastUtil.show(msg,Toast.LENGTH_LONG);
            }

            @Override
            public void onError(Throwable t, int resCode, String msg) {
                ToastUtil.show(msg,Toast.LENGTH_LONG);

            }
        }));


    }


    @Override
    public void start() {

        loadData();
    }
}
